package cn.wolfcode.service.impl;

import cn.wolfcode.domain.MessageBoardZrh;
import cn.wolfcode.mapper.MessageBoardZrhMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IMessageBoardZrhService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MessageBoardZrhServiceImpl implements IMessageBoardZrhService {

    @Autowired
    private MessageBoardZrhMapper messageBoardZrhMapper;


    @Override
    public void save(MessageBoardZrh messageBoardZrh) {
        messageBoardZrh.setReplystatusZrh(false);
        messageBoardZrh.setCreateTimeZrh(new Date());
        messageBoardZrhMapper.insert(messageBoardZrh);
    }

    @Override
    public void delete(Long id) {
        messageBoardZrhMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(MessageBoardZrh messageBoardZrh) {
        messageBoardZrhMapper.updateByPrimaryKey(messageBoardZrh);
    }

    @Override
    public MessageBoardZrh get(Long id) {
        return messageBoardZrhMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<MessageBoardZrh> listAll() {
        return messageBoardZrhMapper.selectAll();
    }

    @Override
    public PageInfo<MessageBoardZrh> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize()); //对下一句sql进行自动分页
        List<MessageBoardZrh> messageBoardZrhs = messageBoardZrhMapper.selectForList(qo); //里面不需要自己写limit
        return new PageInfo<MessageBoardZrh>(messageBoardZrhs);
    }

    @Override
    public void updateReplyStatus(Long id) {
        messageBoardZrhMapper.updateReplyStatus(id);
    }
}
